package stephencarmody.random_rotating_triangles;

import stephencarmody.k8.core.Logic;
import stephencarmody.k8.core.Triangle;

/** Feeds rotating triangles gradually into the engine. */
public class TriangleFeeder extends Logic {

	private int updaterate = 60;
	private boolean paused = false;
	
    private Triangle t1;
    private Triangle t2;
    
    /** Creates a new instance of TriangleFeeder */
    public TriangleFeeder() {
    	setUpdateRate(updaterate);
    }

    public void pause() {
    	if ( paused )
    		setUpdateRate(updaterate);
    	else
    		setUpdateRate(0);
    	paused = !paused;
    }

    /** Called n times a second, where n is defined by setUpdateRate(n). */
    public void update(long time) {
        t1 = new Triangle();
        t1.texture(Main.wood);
        t1.vertices(-1, 1, 0, 1, 0, 0, 0, 2, 0);
        t1.texCoords(0,0,0,1,1,0);
        t2 = new Triangle();
        t2.texture(Main.wood);
        t2.vertices(-1, 1, 0, 0, 2, 0, 1, 0, 0);
        t2.texCoords(0,0,0,1,1,0);
        t1.appendChild(t2);
        
        t1.moveForward(((float)Math.random() * 100) + 5);
        t1.moveRight(((float)Math.random() * 100) - 50);
        t1.moveUp(((float)Math.random() * 100) - 50);
        
        ConstantRotation logic = new ConstantRotation(
           		((float)Math.random() * 0.0000000006f) - 0.0000000003f,
           		((float)Math.random() * 0.0000000006f) - 0.0000000003f,
           		((float)Math.random() * 0.0000000006f) - 0.0000000003f);
        logic.setSceneNode(t1);
    }
    
}
